<template>
	<div class="form-adapt-container layout-pd">
		<el-card shadow="hover" header="输入必填信息后点击退院">
			<el-form :model="form" size="default" label-width="100px" class="mt35 mb35">
				<el-row :gutter="35">
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4" class="mb20">
						<el-form-item label="机构编号">
							<el-input v-model="form.fixmedins_code" placeholder="请输入定点医药机构编号" clearable></el-input>
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4" class="mb20">
						<el-form-item label="就诊ID">
							<el-input v-model="form.mdtrt_id" placeholder="请输入就诊ID" clearable></el-input>
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4" class="mb20">
						<el-form-item label="人员编号">
							<el-input v-model="form.psn_no" placeholder="请输入人员编号" clearable></el-input>
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
		</el-card>
		<el-card shadow="hover" header="录入">
			<el-button @click="back" size="default" class="mt15" type="primary">
				<SvgIcon name="iconfont icon-step" />退院
			</el-button>
		</el-card>
	</div>
</template>

<script lang="ts">
import { toRefs, reactive, defineComponent } from 'vue';
import { Chs9001 } from '/@/Modal/CHS9001'
import { Chs2404 } from '/@/Modal/CHS2404'
import post from '/@/utils/post'
import { ElMessage } from 'element-plus';
import signature from '/@/config/chs/hainan/signature'

export default defineComponent({
	name: 'hainanTuiYuan',
	setup() {
		const state = reactive({
			form: {
				fixmedins_code: '',
				mdtrt_id: '',
				psn_no: '',
			},
		});
		const signIn = async () => {
			let chs = Chs9001.init()
			chs.fixmedins_code = state.form.fixmedins_code
			chs.infno = '9001'
			chs.sign_no = ''
			chs.recer_sys_code = 'MBS_LOCAL'
			chs.opter = '001'
			let result = await post.postList(chs,"http://10.103.129.219:8086/CSB",signature.sign())
			if(result.data.infcode != "0"){
				ElMessage({
					showClose: true,
					duration: 5000,
					message: result.data.err_msg,
					type: 'error',
				})
			}
			return result.data.output.signinoutb.sign_no
		}

		const back = async () => {
			let chs = Chs2404.init()
			chs.sign_no = await signIn()
			chs.infno = '2404'
			chs.mdtrtarea_admvs = '460299'
			chs.insuplc_admdvs = '460000'
			chs.recer_sys_code = 'fsi'
			chs.opter = '001'
			chs.input.data.mdtrt_id = state.form.mdtrt_id
			chs.input.data.psn_no = state.form.psn_no
			let result = await post.postList(chs,"http://10.103.129.219:8086/CSB",signature.sign())
			if(result.data.infcode != "0"){
				ElMessage({
					showClose: true,
					duration: 5000,
					message: result.data.err_msg,
					type: 'error',
				})
			} else {
				ElMessage({
					showClose: true,
					duration: 5000,
					message: '退院成功：'+ result.data.output,
					type: 'success',
				})
			}
		}

		return {
			signIn,
			back,
			...toRefs(state),
		};
	},
});
</script>
